import { arrHasData } from '/@/utils';

export const useUpload = () => {
	const isShowPicSelector = ref(false);
	const isShowVideoSelector = ref(false);
	const isShowFileSelector = ref(false);

	const eventObj = {};
	const getPic = (pic) => {
		if (!arrHasData(pic)) return console.error('no data!');
		eventObj.getPicSrc(pic[0].imgUrl);
		eventObj.getPicSrc = null;
	};
	const getVideo = (videoList) => {
		if (!arrHasData(videoList)) return console.error('no data!');
		eventObj.getVideoSrc(videoList[0].imgUrl);
		eventObj.getVideoSrc = null;
	};
	const getFile = (fileList) => {
		if (!arrHasData(fileList)) return console.error('no data!');
		const { imgUrl, name } = fileList[0];
		eventObj.getFileSrc(imgUrl, name);
		eventObj.getFileSrc = null;
	};
	return {
		eventObj,
		isShowPicSelector,
		isShowVideoSelector,
		isShowFileSelector,
		getPic,
		getVideo,
		getFile,
	};
};
export const useEvent = (tinymce, emit, content) => {
	// 添加相关的事件，可用的事件参照文档=> https://github.com/tinymce/tinymce-vue => All available events
	// 需要什么事件可以自己增加
	function onClick(e) {
		emit('onClick', e, tinymce);
	}
	// 可以添加一些自己的自定义事件，如清空内容
	function clear() {
		content.value = '';
	}
	return {
		onClick,
		clear,
	};
};
